const nums = [1, 3, 4, 1, 2, 3, 1];
const findMatrix = (nums) => {
  let res = [[], [], []];
  let temp = [];
  let temp2 = [];
  let temp3 = [];
  nums.forEach((item, index) => {
    res[0].includes(item) ? temp.push(item) : res[0].push(item);
  });
  if (temp.length) {
    temp.forEach((item, index) => {
      res[1].includes(item) ? temp2.push(item) : res[1].push(item);
    });
  }
  if (temp2.length) {
    temp2.forEach((item, index) => {
      res[2].includes(item) ? temp3.push(item) : res[2].push(item);
    });
  }
  console.log("%c 🥑 res: ", "font-size:20px;background:#4da6ff;color:#fff;", res);
};
const findMatrix2 = (nums) => {
  const res = [];
  nums.forEach((num) => {
    let added = false;
    for (let i = 0; i < res.length; i++) {
      if (!res[i].includes(num)) {
        res[i].push(num);
        added = true;
        break;
      }
    }
    if (!added) {
      res.push([num]);
    }
  });
  return res;
};
// findMatrix(nums);
const res = findMatrix2(nums);
console.log("%c 🥑 res: ", "font-size:20px;background:#4da6ff;color:#fff;", res);
